﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebsiteDataModel;
using System.Text;

public partial class morning_edit : System.Web.UI.Page
{
    int tt;
    int deid
    {
        get
        {
            int.TryParse(Request["id"], out tt);
            return tt;
        }
        set
        {
            tt = value;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        fxrq.Attributes.Add("onfocus", "WdatePicker()");
        psrq.Attributes.Add("onfocus", "WdatePicker()");
        zqhggr.Attributes.Add("onfocus", "WdatePicker()");
        ssrq.Attributes.Add("onfocus", "WdatePicker()");
        if (!IsPostBack)
        {
            string strid = String.IsNullOrEmpty(Request["id"]) ? "" : Request["id"];
            if (deid == 0)
            {
                this.xgid.Value = "";
            }
            else
            {
                this.xgid.Value = strid;
                showInfo();
            }
        }
        if (deid != 0)
        {
            showTzxm();
            showZygd();
            showGgrq();
            showJgyj();
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        //WebsiteDataModel.WebsiteDataEntities de = new WebsiteDataModel.WebsiteDataEntities();
        //XG_Detail[] dl = de.XG_Detail.Where(a => a.id == 1).ToArray();
        saveInfo();
        showInfo();
    }

    /// <summary>
    /// 显示个股详细信息
    /// </summary>
    private void showInfo()
    {
        WebsiteDataModel.WebsiteDataEntities de = new WebsiteDataModel.WebsiteDataEntities();
        XG_Detail[] dl = de.XG_Detail.Where(a => a.id == deid).ToArray();

        if (dl.Length > 0)
        {
            XG_Detail detail = dl[0];
            this.cxfs.Text = detail.cxfs;
            this.djzjzj.Text = DAL.NumFormat.ConvertStringDecimal(detail.Djzjzj);
            this.fxgs.Text = DAL.NumFormat.ConvertStringInt(detail.fxgs);
            this.fxh.Text = DAL.NumFormat.ConvertStringDecimal(detail.fxh);
            this.fxjg.Text = DAL.NumFormat.ConvertStringDecimal(detail.fxjg);
            this.fxmz.Text = DAL.NumFormat.ConvertStringDecimal(detail.fxmz);
            this.fxq.Text = DAL.NumFormat.ConvertStringDecimal(detail.fxq);
            this.fxqy.Text = DAL.NumFormat.ConvertStringDecimal(detail.fxqy);
            this.fxrq.Text = DAL.NumFormat.ConvertStringDateTime(detail.fxrq, "yyyy-MM-dd");
            this.fxsyl.Text = DAL.NumFormat.ConvertStringDecimal(detail.fxsyl);
            this.fxzql.Text = DAL.NumFormat.ConvertStringDecimal(detail.fxzql);
            this.fzcxs.Text = detail.fzcxs;
            //this.glfpzc.Text = detail.glfpzc;
            this.gpdm.Text = detail.gpdm;
            this.gpjc.Text = detail.gpjc;
            this.gsjj.Text = detail.gsjj;
            this.sshy.Text = detail.sshy;

            //收购推荐
            #region
            if (!string.IsNullOrEmpty(detail.sgtj))
            {
                string[] arr = detail.sgtj.Split(',');
                foreach (var m in arr)
                {
                    string[] arr2 = m.Split(':');
                    switch (arr2[0])
                    {
                        case "1":
                            if (arr2[1] == "1")
                                this.sgtj_1.Checked = true;
                            break;
                        case "2":
                            if (arr2[1] == "1")
                                this.sgtj_2.Checked = true;
                            break;
                        case "3":
                            if (arr2[1] == "1")
                                this.sgtj_3.Checked = true;
                            break;
                        case "4":
                            if (arr2[1] == "1")
                                this.sgtj_4.Checked = true;
                            break;
                        case "5":
                            if (arr2[1] == "1")
                                this.sgtj_5.Checked = true;
                            break;
                    }
                }
            }
            #endregion

            this.srspj.Text = DAL.NumFormat.ConvertStringDecimal(detail.spj);
            //this.hsl.Text = DAL.NumFormat.ConvertStringDecimal(detail.hsl);
            //this.kpj.Text = DAL.NumFormat.ConvertStringDecimal(detail.kpj);
            this.mjzj.Text = DAL.NumFormat.ConvertStringDecimal(detail.mjzj);
            this.psbl.Text = DAL.NumFormat.ConvertStringDecimal(detail.psbl);
            this.psdjzj.Text = DAL.NumFormat.ConvertStringDecimal(detail.psdjzj);
            this.psgs.Text = DAL.NumFormat.ConvertStringInt(detail.psgs);
            this.psrq.Text = DAL.NumFormat.ConvertStringDateTime(detail.psrq, "yyyy-MM-dd");
            //this.sgdjzj.Text = DAL.NumFormat.ConvertStringDecimal(detail.sgdjzj);
            this.sgdm.Text = detail.sgdm;
            this.sgsl.Text = DAL.NumFormat.ConvertStringInt(detail.sgsl);
            //this.spj.Text = DAL.NumFormat.ConvertStringDecimal(detail.spj);
            //上市地点特殊处理
            this.ssdd.SelectedValue = detail.ssdd;
            this.ssrq.Text = DAL.NumFormat.ConvertStringDateTime(detail.ssrq, "yyyy-MM-dd");
            this.tjr.Text = detail.tjr;
            this.zcxs.Text = detail.zcxs;
            //this.zf.Text = DAL.NumFormat.ConvertStringDecimal(detail.zf);
            this.zfxgs.Text = DAL.NumFormat.ConvertStringInt(detail.zfxgs);
            this.zqh.Text = detail.zqh;
            this.zqhggr.Text = DAL.NumFormat.ConvertStringDateTime(detail.zqhggr, "yyyy-MM-dd");
            this.zyyw.Text = detail.zyyw;
            this.sgdjzj.Text = DAL.NumFormat.ConvertStringDecimal(detail.sgdjzj);
            txtMgsy11E.Text =Convert.ToString( detail.mgsy11E);
            txtQsycj.Text = Convert.ToString(detail.qsycj);
            txtYlyc10E.Text = Convert.ToString(detail.ylyc10E);
            txtCzjy.Text =detail.czjy;
            txtYcsyl.Text = detail.ycsyl;
        }
    }

    /// <summary>
    /// 修改个股详细信息
    /// </summary>
    private void saveInfo()
    {
        WebsiteDataModel.WebsiteDataEntities de = new WebsiteDataModel.WebsiteDataEntities();
        XG_Detail[] dl = de.XG_Detail.Where(a => a.id == deid).ToArray();

        XG_Detail detail;
        if (dl.Length > 0)
        {
            detail = dl[0];
        }
        else
        {
            detail = new XG_Detail();
        }

        detail.cxfs = this.cxfs.Text;
        detail.Djzjzj = DAL.NumFormat.ConvertDecimal(this.djzjzj.Text);
        detail.fxgs = DAL.NumFormat.ConvertBigInt(this.fxgs.Text);
        detail.fxh = DAL.NumFormat.ConvertDecimal(this.fxh.Text);
        detail.fxjg = DAL.NumFormat.ConvertDecimal(this.fxjg.Text);
        detail.fxmz = DAL.NumFormat.ConvertDecimal(this.fxmz.Text);
        detail.fxq = DAL.NumFormat.ConvertDecimal(this.fxq.Text);
        detail.fxqy = DAL.NumFormat.ConvertDecimal(this.fxqy.Text);
        detail.fxrq = DAL.NumFormat.ConvertDateTime(this.fxrq.Text);
        detail.fxsyl = DAL.NumFormat.ConvertDecimal(this.fxsyl.Text);
        detail.fxzql = DAL.NumFormat.ConvertDecimal(this.fxzql.Text);
        detail.fzcxs = this.fzcxs.Text;
        //this.glfpzc.Text = detail.glfpzc;
        detail.gpdm = this.gpdm.Text;
        detail.gpjc = this.gpjc.Text;
        detail.gsjj = this.gsjj.Text;
        //this.hsl.Text = DAL.NumFormat.ConvertStringDecimal(detail.hsl);
        //this.kpj.Text = DAL.NumFormat.ConvertStringDecimal(detail.kpj);
        detail.sshy = this.sshy.Text;
        detail.spj = DAL.NumFormat.ConvertDecimal(this.srspj.Text);

        //收购推荐
        #region
        string strSgtj = "";
        if (sgtj_1.Checked == true)
            strSgtj += "1:1";
        else
            strSgtj += "1:0";
        if (sgtj_2.Checked == true)
            strSgtj += ",2:1";
        else
            strSgtj += ",2:0";
        if (sgtj_3.Checked == true)
            strSgtj += ",3:1";
        else
            strSgtj += ",3:0";
        if (sgtj_4.Checked == true)
            strSgtj += ",4:1";
        else
            strSgtj += ",4:0";
        if (sgtj_5.Checked == true)
            strSgtj += ",5:1";
        else
            strSgtj += ",5:0";
        detail.sgtj = strSgtj;
        #endregion

        detail.mjzj = DAL.NumFormat.ConvertDecimal(this.mjzj.Text);
        detail.psbl = DAL.NumFormat.ConvertDecimal(this.psbl.Text);
        detail.psdjzj = DAL.NumFormat.ConvertDecimal(this.psdjzj.Text);
        detail.psgs = DAL.NumFormat.ConvertBigInt(this.psgs.Text);
        detail.psrq = DAL.NumFormat.ConvertDateTime(this.psrq.Text);
        //this.sgdjzj.Text = DAL.NumFormat.ConvertStringDecimal(detail.sgdjzj);
        detail.sgdm = this.sgdm.Text;
        detail.sgsl = DAL.NumFormat.ConvertInt(this.sgsl.Text);
        //this.spj.Text = DAL.NumFormat.ConvertStringDecimal(detail.spj);
        //上市地点特殊处理
        detail.ssdd = this.ssdd.SelectedValue;
        detail.ssrq = DAL.NumFormat.ConvertDateTime(this.ssrq.Text);
        detail.tjr = this.tjr.Text;
        detail.zcxs = this.zcxs.Text;
        //this.zf.Text = DAL.NumFormat.ConvertStringDecimal(detail.zf);
        detail.zfxgs = DAL.NumFormat.ConvertBigInt(this.zfxgs.Text);
        detail.zqh = this.zqh.Text;
        detail.zqhggr = DAL.NumFormat.ConvertDateTime(this.zqhggr.Text);
        detail.zyyw = this.zyyw.Text;
        detail.sgdjzj = DAL.NumFormat.ConvertDecimal(this.sgdjzj.Text);
        if (!string.IsNullOrEmpty(txtQsycj.Text))
        {
            detail.qsycj =txtQsycj.Text;
        }
        if (!string.IsNullOrEmpty(txtYlyc10E.Text))
        {
            detail.ylyc10E = decimal.Parse(txtYlyc10E.Text);
        }
        if (!string.IsNullOrEmpty(txtMgsy11E.Text))
        {
            detail.mgsy11E = decimal.Parse(txtMgsy11E.Text);
        }
        detail.ycsyl = txtYcsyl.Text;
        detail.czjy = txtCzjy.Text;
        if (dl.Length <= 0)
        {
            detail.url = "";
            de.XG_Detail.AddObject(detail);
        }
        int num = de.SaveChanges();

    }

    /// <summary>
    /// 显示IPO公告日程
    /// </summary>
    private void showGgrq()
    {
        WebsiteDataEntities de = new WebsiteDataEntities();
        var re = de.XG_ggrq.Where(a => a.xgid == deid);
        RepeaterGGRQ.DataSource = re;
        RepeaterGGRQ.DataBind();
    }

    /// <summary>
    /// 显示投资项目
    /// </summary>
    private void showTzxm()
    {
        WebsiteDataEntities de = new WebsiteDataEntities();
        var re = de.XG_Invset.Where(a => a.id == deid);
        Repeater1.DataSource = re;
        Repeater1.DataBind();
    }

    /// <summary>
    /// 显示主要股东信息
    /// </summary>
    private void showZygd()
    {
        WebsiteDataEntities de = new WebsiteDataEntities();
        var re = de.XG_Partner.Where(a => a.id == deid);
        Repeater2.DataSource = re;
        Repeater2.DataBind();
    }

    /// <summary>
    /// 显示机构研究
    /// </summary>
    private void showJgyj()
    {
        WebsiteDataEntities de = new WebsiteDataEntities();
        var re = de.XG_GG.Where(a => a.tid == deid);
        Repeater3.DataSource = re;
        Repeater3.DataBind();
    }
}